package cn.njxzc.exercises;

import java.io.BufferedWriter;
import java.io.FileWriter;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.BufferedReader;

public class Pro9_1 {

	static String readLine() throws IOException {
		String str = null;
		InputStreamReader isr = new InputStreamReader(System.in);
		BufferedReader buf = new BufferedReader(isr);
		str = buf.readLine();

		return str;
	}

	public static void main(String[] args) throws IOException {
//		if (args.length != 1) {
//			System.out.println("java readkeyborad filename");
//			System.exit(0);
//		}
		BufferedWriter wr = null;
		try {
			System.out.println("please input some words:");
			wr = new BufferedWriter(new FileWriter("readme.txt"));
			String lineString;
			while ((lineString = readLine()) != null
					&& !lineString.equals("quit"))
				wr.write(lineString + "\n");
		} catch (Exception e) {
			// TODO: handle exception
			System.out.println(e);

		}finally{
			try {
				wr.close();
				System.out.println("file is closed");
			} catch (Exception e2) {
				// TODO: handle exception
				System.out.println(e2);
			}
		}

	}

}
